package PerlIO::via::Pipe;

use strict;
use warnings;
require 5.008;


our $VERSION = '0.01';


use base 'Exporter';


our %EXPORT_TAGS = (
    util  => [ qw(set_io_pipe) ],
);


our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] };


sub set_io_pipe ($) {
    our $pipe = shift;
}


sub PUSHED {
    my ($class, $mode) = @_;
    return -1 if $mode ne 'r';
    my $buf = '';
    bless \$buf, $class;
}


sub FILL {
    my ($self, $fh) = @_;
    my $line = <$fh>;
    return unless defined $line;
    our $pipe;
    $pipe->filter($line);
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - PerlIO layer to filter input through a Text::Pipe

=head1 SYNOPSIS

    use PerlIO::via::Pipe 'set_io_pioe';
    use Text::Pipe 'pipe';

    my $pipe = pipe(...) | pipe(...);

    open my $file, '<:via(Pipe)', 'foo.txt'
        or die "can't open foo.txt $!\n";


=head1 DESCRIPTION

This package implements a PerlIO layer for reading files only. It exports, on
request, a function C<set_io_pipe> that you can use to set a L<Text::Pipe>
pipe. If you then use the C<Pipe> layer as shown in the synopsis, the input
gets filtered through the pipe.

{% PROCESS standard_pod %}

=cut

